package com.cn.wanxi.dao.impl;

import com.cn.wanxi.dao.CuisineDao;
import com.cn.wanxi.model.CuisineModel;
import com.cn.wanxi.util.JDBC;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CuisineImpl implements CuisineDao {
    @Override
    public int add(CuisineModel cuisineModel) {
        return 0;
    }

    @Override
    public List<CuisineModel> findAll(CuisineModel cuisineModel) {

//        String sql = "select * from cuisine where name='" + cuisineModel.getName() + "'";
        return null;

    }

    @Override
    public int update(CuisineModel cuisineModel) {
//        String sql = "update cuisine set name='" + cuisineModel.getName() + "' , id=" + cuisineModel.getId() + " ";
        String sql = "update cuisine set name=? , id=? ";
        List<Object> list = new ArrayList<>();
        list.add(cuisineModel.getName());
        list.add(cuisineModel.getId());
        return JDBC.updatea(sql, list);
    }

    @Override
    public CuisineModel findById(CuisineModel cuisineModel) {
        return null;
    }

    @Override
    public int delete(CuisineModel cuisineModel) {
        return 0;
    }

    @Override
    public int getCount(CuisineModel cuisineModel) {
        return 0;
    }

    @Override
    public List<CuisineModel> findAllIsShow() {
        String sql = "select * from cuisine where is_show=1";
        ResultSet resultSet = JDBC.query(sql);
        List<CuisineModel> list = new ArrayList<>();

        try {
            while (resultSet.next()) {
                CuisineModel model = new CuisineModel();
                model.setName(resultSet.getString("name"));
                model.setId(resultSet.getInt("id"));
                list.add(model);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
}
